<!DOCTYPE html>
<html lang="ko">
<head>
	<meta charset="UTF-8">
	<title>Form Feedback</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- Bootstrap -->
	<link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
	<div class="container">
		<div class="row">
        	<div class="span12">
	<?php # Script 2.4 - handle_form02.php
	
	// Validate the name:
	if (!empty($_REQUEST['name'])) {
		$name = $_REQUEST['name'];
	} else {
		$name = NULL;
		echo '<p class="text-error">You forgot to enter your name!</p>';
	}

	// Validate the email:
	if (!empty($_REQUEST['email'])) {
		$email = $_REQUEST['email'];
	} else {
		$email = NULL;
		echo '<p class="text-error">You forgot to enter your email address!</p>';
	}

	// Validate the comments:
	if (!empty($_REQUEST['comments'])) {
		$comments = $_REQUEST['comments'];
	} else {
		$comments = NULL;
		echo '<p class="text-error">You forgot to enter your comments!</p>';	
	}

	// Validate the gender:
	if (isset($_REQUEST['gender'])) {
		$gender = $_REQUEST['gender'];

		if ($gender == 'M') {
			echo '<p><b>Good day, Sir!</b></p>';
		} elseif ($gender == 'F') {
			echo '<p><b>Good day, Madam!</b></p>';
		} else { // Unacceptable value.
			$gender = NULL;
			echo '<p class="text-error">Gender should be either "M" or "F"!</p>';		
		}
	} else { // $_REQUEST['gender'] is not set.
		$gender = NULL;
		echo '<p class="text-error">You forgot to select your gender!</p>';
	}

	// If everything is OK, print the message:
	if ($name && $email && $gender && $comments) {
		echo "<p>Thank you, <b>$name</b>, for the following comments:<br/>
		<tt>$comments</tt></p>
		<p>We will reply to you at <i>$email</i></p>\n";
	} else { // Missing form value.
		echo '<p class="text-error">Please go back and fill out the form again.</p>';
	}

	?>
			</div>
		</div>
	</div>
	<script src="http://code.jquery.com/jquery.js"></script>
	<script src="../js/bootstrap.min.js"></script>
</body>
</html>